import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86131
 * Date: 2023-11-15
 * Time: 14:54
 */
public class Role {
    private String name;
    private int blood;
    private char gender;
    private String face;  //随机

    String[] boyface = {"风流俊雅", "气宇轩昂", "相貌英俊", "五官端正", "相貌平平", "一塌糊涂", "面目狰狞"};
    String[] girlface = {"美丽绝伦", "沉鱼落雁", "亭亭玉立", "身材姣好", "相貌平平", "相貌简陋", "惨不忍睹"};


    public Role() {
    }

    public Role(String name, int blood, char gender) {
        this.name = name;
        this.blood = blood;
        this.gender = gender;
        //随机长相
        setFace(gender);
    }


    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public String getFace() {
        return face;
    }

    public void setFace(char gender) {
        Random r = new Random();

        if (gender == '男') {
            //从boyface随机长相
            int index = r.nextInt(boyface.length);
            this.face = boyface[index];
        } else if (gender == '女') {
            //从girlface随机长相
            int index = r.nextInt(girlface.length);
            this.face = girlface[index];
        } else {
            this.face = "面目狰狞";

        }
        this.face = face;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    //定义一个方法用于攻击别人
    //思考:谁攻击谁
    //Role r1 = new Role();
    //Role r2 = new Role();
    //r1.攻击(r2);
    //方法的调用者去攻击参数
    public void attack(Role role) {
        //计算造成的伤害
        Random r = new Random();
        //伤害
        int hurt = r.nextInt(20) + 1; //1-20的随机数(0~19)所以+1

        //挨揍人剩余血量
        int remainBlood = role.getBlood() - hurt;
        //对剩余血量做验证,如果为负数,就修改为0
        remainBlood = remainBlood < 0 ? 0 : remainBlood;
        //修改挨揍人的血量
        role.setBlood(remainBlood);

        //this 表示方法的调用者
        System.out.println(this.getName() + "举起拳头,打了" + role.getName() + "一下,造成" + hurt + "点伤害," + role.getName() + "还剩下" + remainBlood + "点血");
    }

    //展示角色的信息
    public void showRoleInfo() {
        System.out.println("姓名为:" + getName());
        System.out.println("血量为:" + getBlood());
        System.out.println("性别为:" + getGender());
        System.out.println("长相为:" + getFace());
    }

}
